<?php

class Activator implements PrspActivator{

	public function start(){
		
		//fixed query string
		$array = array();
		if($_SERVER['QUERY_STRING']===''){
			parse_str( substr($_SERVER['REQUEST_URI'], 2) ,$array);
		}
		foreach ($array as $key => $value){
			$_REQUEST[$key] = $value;
		}

		//Logger status
		Logger::setEnabled( isset($GLOBALS['PRSP']['Debugger']) && $GLOBALS['PRSP']['Debugger'] );

		if( isset($_REQUEST['_lang']) ){
			I18N::setLanguage($_REQUEST['_lang']);
		}

		//Plugin information
		if( isset($_REQUEST['_plugininfo']) ){
			echo '<h2>PRSP Core Information</h2>';
			echo '<table border="1">';
			echo '	<tr>';
			echo '		<th>Version</th>';
			echo '		<td>'.$GLOBALS['PRSP']['Version'].'</td>';
			echo '	</tr>';
			echo '	<tr>';
			echo '		<th>Released</th>';
			echo '		<td>'.$GLOBALS['PRSP']['Released'].'</td>';
			echo '	</tr>';
			echo '	<tr>';
			echo '		<th>PHP Report</th>';
			echo '		<td>'.($GLOBALS['PRSP']['ErrorReport']?'OPEN':'CLOSE').'</td>';
			echo '	</tr>';
			echo '	<tr>';
			echo '		<th>PHP Plugins Folder</th>';
			echo '		<td>'.$GLOBALS['PRSP']['Folders']['Plugins'].'</td>';
			echo '	</tr>';
			echo '	<tr>';
			echo '		<th>PHP Plugin Configuration Folder</th>';
			echo '		<td>'.$GLOBALS['PRSP']['Folders']['Configuration'].'</td>';
			echo '	</tr>';
			echo '	<tr>';
			echo '		<th>PHP Plugins Library Folder</th>';
			echo '		<td>'.$GLOBALS['PRSP']['Folders']['Library'].'</td>';
			echo '	</tr>';
			echo '	<tr>';
			echo '		<th>DefaultController</th>';
			echo '		<td>'.$GLOBALS['PRSP']['DefaultController'].'</td>';
			echo '	</tr>';
			echo '</table>';
			
			echo '<h2>PRSP Plugins Information</h2>';
			echo '<table border="1">';
			echo '	<tr>';
			echo '		<th>Plugin ID</th>';
			echo '		<th>Version</th>';
			echo '		<th>Enabled</th>';
			echo '		<th>AutoStart</th>';
			echo '	</tr>';
			foreach ( Register::getPlugins() as $pluginId => $plugin ){
				echo '	<tr>';
				echo '		<td>'.$pluginId.'</td>';
				echo '		<td>'.$plugin['Version'].'</td>';
				echo '		<td>'.($plugin['Enabled']?'Yes':'No').'</td>';
				echo '		<td>'.($plugin['AutoStart']?'Yes':'No').'</td>';
				echo '	</tr>';
			}
			echo '</table>';
			exit(0);
		}
	}
	
	public function stop(){
		Viewer::render();
	}
	
}

?>